import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  CreateDateColumn,
  ManyToOne,
  JoinColumn,
} from 'typeorm';
import { Restaurant } from './restaurant.entity';

@Entity('draw_histories')
export class DrawHistory {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @Column({ type: 'uuid' })
  restaurant_id: string;

  @Column({ type: 'varchar', length: 255 })
  restaurant_name: string;

  @Column({ type: 'varchar', length: 100 })
  restaurant_category: string;

  @Column({ type: 'timestamp' })
  draw_time: Date;

  @CreateDateColumn({ type: 'timestamp' })
  created_at: Date;

  // 关联关系
  @ManyToOne(() => Restaurant, (restaurant) => restaurant.drawHistories, {
    onDelete: 'CASCADE',
  })
  @JoinColumn({ name: 'restaurant_id' })
  restaurant: Restaurant;
}
